#include "devicemap.h"
#include "ui_devicemap.h"
#include <QString>
#include <QStringList>
#include <QMessageBox>
#include <QDebug>
#include <QPainter>

deviceMap::deviceMap(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::deviceMap)
{
    ui->setupUi(this);

    x=y=-1;
    //QMessageBox::critical(this,"无设备位置信息","请为设备选择位置",QMessageBox::Ok);
}
//创建同时设定位置
deviceMap::deviceMap(QWidget *parent,int row, int x, int y):
    QWidget(parent),
ui(new Ui::deviceMap)
{
    ui->setupUi(this);

    this->x=x;
    this->x=y;
    this->row = row;
}

deviceMap::~deviceMap()
{
    delete ui;
}
//鼠标点击事件
void deviceMap::mousePressEvent(QMouseEvent *event)
{
    qDebug()<<"鼠标事件触发:"<<event->x()<<","<<event->y();

    QString value=QString("%1,%2").arg(event->x()).arg(event->y());
    ui->label_2->setText(value);

    this->x=event->x();
    this->y=event->y();
/*
    if(x!=-1){
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);

        // 获取窗口的宽度和高度
        int width = this->width();
        int height = this->height();

        // 设置线条的颜色和宽度
        QPen pen(Qt::red, 2); // 黑色，宽度为2
        painter.setPen(pen);

        // 绘制一条从窗口左边到右边的水平线，位于窗口高度的中间
        painter.drawLine(0, y, width, y);
        painter.drawLine(x, 0, x, height);
    }*/

}

//回退按钮
void deviceMap::on_pushButton_clicked()
{
    close();
}
//设定地址选项
void deviceMap::on_pushButton_2_clicked()
{
    QString val = ui->label_2->text();
    QStringList list= val.split(",");//打断
    //触发信号
    qDebug()<<"信号发回消息"<<row<<list[0]<<list[1];
    emit signal_return_A(row,list[0].toInt(),list[1].toInt());

    close();
}
